package com.result.demo.modules.goods.controller;

import com.alibaba.fastjson.JSONObject;
import com.result.demo.global.annotation.ResponseResult;
import com.result.demo.global.config.GlobalConfig;
import com.result.demo.global.enums.ResultCode;
import com.result.demo.global.exception.BizException;
import com.result.demo.modules.goods.service.GoodsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/*
所有controller 类都必须用@ResponseResult 标签，否则会提示无效的api
所有错误信息返回通过自定义异常的方式返回，需要在ResultCode 里添加返回异常信息
通过  throw  new BizException(xxxxx.YYYYY) 形式返回系统会自动捕捉异常并返回
系统异常直接抛出，统一捕捉处理
 */


/**
 * @author chao.z
 */
@RestController
@RequestMapping("goods")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@ResponseResult
@Slf4j
public class GoodsController {




    @GetMapping("product")
    @ResponseBody
    public  void product(){
    }

    @PostMapping("test")
    @ResponseBody
    public  HashMap test(@RequestBody JSONObject jsonObject){
        boolean signCheck = GlobalConfig.getSignCheck();
        log.info("demo........{},{}",jsonObject);

        List<Map<String,Object>> list = new ArrayList<>();
        Map<String,Object> map  = new HashMap<>();
        map.put("name","jack");
        list.add(map);
//        log.info("查询的数据:{}",test);
        return new HashMap<>();
    }
    @GetMapping("user")
    @ResponseBody
    public boolean insert(String name,Integer age) throws Exception {

        log.info("demo........{},{}",name,age);
        System.out.println("开始新增...");
        //如果姓名为空就手动抛出一个自定义的异常！
        throw  new BizException(ResultCode.API_NOT_EXIST);

    }
    @GetMapping("excep")
    @ResponseBody
    public boolean excep() throws Exception {

        //如果姓名为空就手动抛出一个自定义的异常！
            throw  new Exception();


    }
}
